package com.threeti.mecool.core.application;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.threeti.mecool.core.domain.model.project.ProjectCategory;
import com.threeti.mecool.core.infrastructure.persistence.project.ProjectCategoryRepository;

@Service
public class AdminServiceImpl implements AdminService {
  @Autowired
  private ProjectCategoryRepository projCatRepo;

  @Override
  @Transactional
  public ProjectCategory storeProjectCategory(ProjectCategory projectCategory) {
    try {
      return projCatRepo.saveAndFlush(projectCategory);
    } catch (DataIntegrityViolationException e) {
      throw new RuntimeException("存在同名项目类型");
    }
  }

}
